//
//  UFOLQCSkillVCC.m
//  unrivalledForUniverse
//
//  Created by dllo on 1/21/16.
//  Copyright © 2016 dllo. All rights reserved.
//

#import "UFOLQCSkillVCC.h"

#import "UFOLQCSkillCollectionView.h"
#import "UFOheroModel.h"
#import "LQCAFNetTool.h"

@interface UFOLQCSkillVCC ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, retain) UICollectionView *skillCollectV;
@property (nonatomic, retain) NSMutableArray *heroArr;

@end

@implementation UFOLQCSkillVCC

- (void)dealloc
{
    [_heroArr release];
    [_skillCollectV release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    button.frame = CGRectMake(5, 25, 30, 30);
    [button addTarget:self action:@selector(fanhuiAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    [self createCollectionV];
    [self createSubViews];
}

- (void)fanhuiAction
{
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}

- (void)createCollectionV{
    UICollectionViewFlowLayout *flow = [[[UICollectionViewFlowLayout alloc] init] autorelease];
    
    flow.minimumLineSpacing = 10 * SCREENHEIGHT / HEIGHTSIXP;
    flow.minimumInteritemSpacing = 10 * SCREENWIDTH / WIDTHSIXP;
    flow.headerReferenceSize = CGSizeMake(0, 0);
    flow.footerReferenceSize = CGSizeMake(0, 0);
    flow.itemSize = CGSizeMake(((SCREENWIDTH - 10 * 4 * SCREENWIDTH / WIDTHSIXP) / 3.0), ((SCREENWIDTH - 10 * SCREENWIDTH / WIDTHSIXP) / 3));
    flow.sectionInset = UIEdgeInsetsMake(10 * SCREENHEIGHT / HEIGHTSIXP, 10 * SCREENWIDTH / WIDTHSIXP, 10 * SCREENHEIGHT / HEIGHTSIXP, 10 * SCREENWIDTH / WIDTHSIXP);
    flow.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    self.skillCollectV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 55, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flow];
    self.skillCollectV.backgroundColor = [UIColor colorWithWhite:0.902 alpha:1.000];
    
    self.skillCollectV.delegate = self;
    self.skillCollectV.dataSource = self;
    self.skillCollectV.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:self.skillCollectV];
    
    [_skillCollectV release];
    
    [self.skillCollectV registerClass:[UFOLQCSkillCollectionView class] forCellWithReuseIdentifier:@"cell"];
}

- (void)createSubViews
{
     self.heroArr = [NSMutableArray array];
    [LQCAFNetTool getNetWithURL:@"http://v.wanmeixx.com/Ajax20151126.ashx?g=1&act=GetHeroList" body:nil headFile:nil responseStyle:LQCJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = [dic objectForKey:@"Data"];
        self.heroArr = [UFOheroModel baseModelWithArr:arr];
        [self.skillCollectV reloadData];
        
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
    }];
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.heroArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UFOLQCSkillCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    UFOheroModel *heroM = [self.heroArr objectAtIndex:indexPath.item];
    
    NSURL *imageUrl = [NSURL URLWithString:heroM.Pic];
    
    
    [cell.image sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"zanweitu"]];
    
    cell.label.text = heroM.CName;
    
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
